package com.kogi.androidpatt.dealing.options;



import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import com.kogi.patterns.R;
import com.kogi.patterns.dummy;
import com.kogi.patterns.main;
import com.navigation.segmented.EnergyEntry;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.DataSetObserver;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class ImageAdapterDealing extends BaseAdapter {
    private Context mContext;
    private int a=0;
    Context context;
    LayoutInflater li;
    Activity actv;
    ArrayList<String> texts;
    ArrayList<Integer> images;
    Intent con ;
    private int items=0;
    public ImageAdapterDealing(Context c) {
        mContext = c;
    }

    public ImageAdapterDealing(ChangeView c, Context aa,LayoutInflater tr,Activity at) {
    	mContext = c;
    	context=aa;
    	li=tr;
    	actv=at;
    	
    	 images = new ArrayList<Integer>();
         texts = new ArrayList<String>();
         readFile();
	}

	public int getCount() {
        return items;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(final int position, View convertView, ViewGroup parent) {
    	 ImageView imageView;
    	 LinearLayout ll;
         if (convertView == null) {  // if it's not recycled, initialize some attributes
            
        	 imageView = new ImageView(mContext);
             imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
             //imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
             imageView.setPadding(8, 8, 8, 8);
             imageView.setTag(a);
         } else {
             imageView = (ImageView) convertView;
         }

         imageView.setImageResource(images.get(position));
         return imageView;
    }
    
    public void Fillflags(){
    	//mThumbIds = new Integer[224];
    	
    	InputStream in;
	  	
    	ContextWrapper Fcont=(ContextWrapper) context;
		in= Fcont.getResources().openRawResource(R.raw.coutries_flags);
    	
    	
		try {
			
			 	//StringBuffer inLine = new StringBuffer();
    	        InputStreamReader isr = new InputStreamReader(in);
    	 
    	        BufferedReader inRd = new BufferedReader(isr);
    	        
    
    	        String text;
    	         
    	        while ((text = inRd.readLine()) != null) {
    	           
    	         String line[]= text.split(";"); 
    	            
    	            
    	        }
    	        in.close();
    	        
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

    // references to our images
    private Integer[] mThumbIds = {
            R.drawable.bl_lgflag, R.drawable.br_lgflag,
            R.drawable.ci_lgflag, R.drawable.co_lgflag,
            R.drawable.ar_lgflag, R.drawable.gy_lgflag,
            R.drawable.ec_lgflag, R.drawable.ns_lgflag,
            R.drawable.pa_lgflag, R.drawable.pe_lgflag,
            R.drawable.uy_lgflag, R.drawable.ve_lgflag
    };
    
    public void readFile(){
  	  InputStream in;
	  	
    	ContextWrapper Fcont=(ContextWrapper) context;
		in= Fcont.getResources().openRawResource(R.raw.coutries_flags);
    	
    	
		try {
			
			 	//StringBuffer inLine = new StringBuffer();
    	        InputStreamReader isr = new InputStreamReader(in);
    	 
    	        BufferedReader inRd = new BufferedReader(isr);
    	      String text;
    	      
    	       	      
    	          
    	        while ((text = inRd.readLine()) != null) {
    	           
    	         String line[]= text.split(";"); 
    	        String mDrawableName = line[1];
    	        Integer tmp=actv.getResources().getIdentifier(mDrawableName , "drawable", actv.getPackageName());
    	        images.add(tmp);
    	        texts.add(line[0]); 
    	         
    	        Log.d(line[0], line[1]);
    	        
    	         items++;
    	            
    	        }
    	        in.close();
    	        
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

	
}
